package com.dianping.cat.home.dependency.graph.transform;

import com.dianping.cat.home.dependency.graph.IEntity;
import com.dianping.cat.home.dependency.graph.IVisitor;
import com.dianping.cat.home.dependency.graph.entity.TopologyEdge;
import com.dianping.cat.home.dependency.graph.entity.TopologyGraph;
import com.dianping.cat.home.dependency.graph.entity.TopologyNode;
import java.util.Stack;

public class DefaultMerger
  implements IVisitor
{
/*  13 */   private Stack<Object> m_objs = new Stack();

  private TopologyGraph m_topologyGraph;


  public DefaultMerger() {}

  public DefaultMerger(TopologyGraph topologyGraph) {
/*  21 */     this.m_topologyGraph = topologyGraph;
/*  22 */     this.m_objs.push(topologyGraph);
  }


/*  26 */   public TopologyGraph getTopologyGraph() { return this.m_topologyGraph; }



/*  30 */   protected Stack<Object> getObjects() { return this.m_objs; }


  public <T> void merge(IEntity<T> to, IEntity<T> from) {
/*  34 */     this.m_objs.push(to);
/*  35 */     from.accept(this);
    this.m_objs.pop();
  }


/*  40 */   protected void mergeTopologyEdge(TopologyEdge to, TopologyEdge from) { to.mergeAttributes(from); }



/*  44 */   protected void mergeTopologyGraph(TopologyGraph to, TopologyGraph from) { to.mergeAttributes(from); }



/*  48 */   protected void mergeTopologyNode(TopologyNode to, TopologyNode from) { to.mergeAttributes(from); }



  public void visitTopologyEdge(TopologyEdge from) {
/*  53 */     TopologyEdge to = (TopologyEdge)this.m_objs.peek();

/*  55 */     mergeTopologyEdge(to, from);
/*  56 */     visitTopologyEdgeChildren(to, from);
  }


  protected void visitTopologyEdgeChildren(TopologyEdge to, TopologyEdge from) {}


  public void visitTopologyGraph(TopologyGraph from) {
/*  64 */     TopologyGraph to = (TopologyGraph)this.m_objs.peek();

/*  66 */     mergeTopologyGraph(to, from);
/*  67 */     visitTopologyGraphChildren(to, from);
  }

  protected void visitTopologyGraphChildren(TopologyGraph to, TopologyGraph from) {
/*  71 */     for (TopologyNode source : from.getNodes().values()) {
/*  72 */       TopologyNode target = to.findTopologyNode(source.getId());

/*  74 */       if (target == null) {
/*  75 */         target = new TopologyNode(source.getId());
/*  76 */         to.addTopologyNode(target);
      }

/*  79 */       this.m_objs.push(target);
/*  80 */       source.accept(this);
/*  81 */       this.m_objs.pop();
    }

/*  84 */     for (TopologyEdge source : from.getEdges().values()) {
/*  85 */       TopologyEdge target = to.findTopologyEdge(source.getKey());

/*  87 */       if (target == null) {
/*  88 */         target = new TopologyEdge(source.getKey());
/*  89 */         to.addTopologyEdge(target);
      }

/*  92 */       this.m_objs.push(target);
/*  93 */       source.accept(this);
/*  94 */       this.m_objs.pop();
    }
  }


  public void visitTopologyNode(TopologyNode from) {
/* 100 */     TopologyNode to = (TopologyNode)this.m_objs.peek();

/* 102 */     mergeTopologyNode(to, from);
/* 103 */     visitTopologyNodeChildren(to, from);
  }

  protected void visitTopologyNodeChildren(TopologyNode to, TopologyNode from) {}
}


/* Location:              /Users/hanfei/Documents/apache-tomcat-9.0.24/webapps/cat/WEB-INF/classes/!/com/dianping/cat/home/dependency/graph/transform/DefaultMerger.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       1.0.7
 */